import json
import os
import PIL
from PIL import Image


# 1.
# file_dir = r'I:\0_Deep_Learning\磁瓦\磁瓦数据集_1_3_正面--sss\1工位\dataset/'

# val_file = open('valid.txt', 'r')
# train_file = open('train.txt', 'r')

# val_f = []
# train_f = []
# for j in val_file:
#     val_f.append(j)

# write_file_name = r'labels.txt'
# write_file = open(write_file_name, "w", encoding='utf-8')
# for g in train_file:
#     if g not in val_f:
#         write_file.write(g)
#         print(g)





# file_list = os.listdir(file_dir)
# idx_start = 1

# for i, t in enumerate(txt_file):
#     name, _ = t.split('.')
#     name_jpg, name_json = os.path.join(file_dir, name + '.jpg'), os.path.join(file_dir, name + '.json')

#     new_name_jpg = file_dir + 'ciwa_%07d' % (i+idx_start) + '.jpg'
#     new_name_json = file_dir + 'ciwa_%07d' % (i+idx_start) + '.json'
#     os.rename(name_jpg, new_name_jpg)
#     os.rename(name_json, new_name_json)
#     print("文件%s重命名成功,\t新的文件名为%s" % (name_jpg, new_name_jpg))
#     print("文件%s重命名成功,\t新的文件名为%s" % (name_json, new_name_json))



# 2.
file_dir = r'I:\0_Deep_Learning\磁瓦\磁瓦数据集_1_3_正面--sss\1工位\dataset/'

file_list = os.listdir(file_dir)
idx_start = 0

for i, name in enumerate(file_list):
    used_name = os.path.join(file_dir, name)
    i += 1
    new_name = file_dir + 'wuzi_hangci_ay_%04d' % (i+idx_start) + '.jpg'
    # os.rename(used_name, new_name)
    print("文件%s重命名成功,\t新的文件名为%s" %(used_name, new_name))